package com.wanfajie.smsdistribute.db.bean.sms

import android.app.Activity
import android.telephony.SmsManager
import com.j256.ormlite.field.DatabaseField
import com.j256.ormlite.table.DatabaseTable

@DatabaseTable(tableName = "sd_sms_message_part")
data class SmsPartBean(
        @DatabaseField(columnName = FIELD_ID, foreign = true)
        val sms: SmsBean?,

        @DatabaseField(columnName = FIELD_RESULT, defaultValue = "$DEFAULT_RESULT_CODE")
        val resultCode: Int
) {

    constructor() : this(null, DEFAULT_RESULT_CODE)

    companion object {
        const val FIELD_ID = "id"
        const val FIELD_TS = "received_timestamp"
        const val FIELD_RESULT = "result_code"

        private const val DEFAULT_RESULT_CODE = 255

        const val RESULT_WAITING = Int.MIN_VALUE
        const val RESULT_OK = Activity.RESULT_OK
        const val NO_RESULT = DEFAULT_RESULT_CODE

        /** Generic failure cause */
        const val RESULT_ERROR_GENERIC_FAILURE    = SmsManager.RESULT_ERROR_GENERIC_FAILURE
        /** Failed because radio was explicitly turned off */
        const val RESULT_ERROR_RADIO_OFF          = SmsManager.RESULT_ERROR_RADIO_OFF
        /** Failed because no pdu provided */
        const val RESULT_ERROR_NULL_PDU           = SmsManager.RESULT_ERROR_NULL_PDU
        /** Failed because service is currently unavailable */
        const val RESULT_ERROR_NO_SERVICE         = SmsManager.RESULT_ERROR_NO_SERVICE
    }

    @DatabaseField(columnName = FIELD_TS)
    val receivedTimestamp: Long = System.currentTimeMillis()
}